<?
session_start();
include("config.php");
if ($_SESSION['admin']!="OK")
{
	echo "<script language='javascript'>alert('Please Log in first');window.location.href='login.php';</script>";
	exit;
}
else
{

	if ($_POST["actions"]=="1")
	{
		$choice=addslashes(trim($_POST["choice"]));
		if (empty($choice))
		{
			echo "<script language='javascript'>alert('The content of option cannot be empty');history.go(-1);</script>";
			exit;
		}
		else
		{
			$conn=mysql_connect($host,$user,$password);
			mysql_select_db($db);
			mysql_query("set names GB2312");
			$query="update vote_choice set choice='".$choice."',IsOptions='".$_POST["currents"]."' where id='".$_POST["titleid"]."'";
			$result=mysql_query($query);
			echo "<script language='javascript'>alert('Successfully Edited');history.go(-2);</script>";
		}
	}
	else
	{
		$conn=mysql_connect($host,$user,$password);
		mysql_select_db($db);
		mysql_query("SET NAMES UTF8");
		$query="select * from vote_choice where id=".$_GET["id"];
		$result=mysql_query($query);
		$row = mysql_fetch_array($result);

?>
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>Questionnaire Survey System --- TMM 2012</title> 
<link href="main.css" rel="stylesheet" type="text/css" />
</head> 
<body>
<div id=main>
<div class=title>Edit vote options</div>
<div id="menu">
  <ul>
		<li><a href='admin.php'>Administraction</a></li>
		<li><a href="editadmin.php">Your Account</a></li>
		<li><a href="addtitle.php" class="top">Add vote topic</a></li>
		<li><a href="showvote.php" target="_blank">Vote result</a></li>
		<li><a href="javascript:$msg=confirm('Are u sure to clean the result?');$msg?window.location.href='clearResult.php':history.go(0);">Delete Result</a></li>
		<li><a href="loginout.php">Log out</a></li>
		<li><a href="index.php" target="_blank">Home</a></li> 
  </ul>
</div>
<form action="" method="post" name="addtitle" id="addtitle">
  <div class=main1>

	  <div class="user2">Options: <input name="choice" type="text" class="inputs" id="choice" value=<?=stripslashes($row["choice"]);?> size="100">no larger than 200</div>
  </div>
  <div class=main1>
	  <div class="user3">Default or not?
<?
		if ($row["IsOptions"]=="a")
		{
?>
		<input type="radio" name="currents" value="a" checked>Yes
		<input type="radio" name="currents" value="b">No
<?
		}
		else
		{
?>
		<input type="radio" name="currents" value="a">Yes
		<input type="radio" name="currents" value="b" checked>No
<?
		}
?>
	  </div>
  </div>
  <div class=main1>
	  <div class="submit3"><input type="submit" name="Submit" value="Submit" class="inputs">
					  <input type="reset" name="Submit2" value="reset" class="inputs" />
					  <input name="actions" type="hidden" id="actions" value="1"><input name="titleid" type="hidden" id="titleid" value="<?=$_GET["id"];?>">
	  </div>
  </div>
  </form>
<?
	}
} 
?> 
</div>
<br>
<center>CopyRight@FengYL</center>
</body>
</html>
